[% setvar title Make subroutines' prototypes accessible from Perl %]
<div id="archive-notice">
    <h3>This file is part of the Perl 6 Archive</h3>
    <p>To see what is currently happening visit <a href="http://www.perl6.org/">http://www.perl6.org/</a></p>
</div>
<div class='pod'>
<a name='TITLE'></a><h1>TITLE</h1>
<p>Make subroutines' prototypes accessible from Perl</p>
<a name='VERSION'></a><h1>VERSION</h1>
<pre>  Maintainer: Simon Cozens &lt;<a href='mailto:simon@brecon.co.uk'>simon@brecon.co.uk</a>&gt;
  Date: 25 Sep 2000
  Mailing List: <a href='mailto:perl6-language-subs@perl.org'>perl6-language-subs@perl.org</a>
  Number: 298
  Version: 1
  Status: Developing</pre>
<a name='ABSTRACT'></a><h1>ABSTRACT</h1>
<p>Allow sub prototypes to be got and set by Perl at compile time.</p>
<a name='DESCRIPTION'></a><h1>DESCRIPTION</h1>
<p>The motivation behind this RFC is to allow subroutine attributes to
define canned &quot;prototype classes&quot;. As a very trivial example:</p>
<pre>    use attributes::prototype 'a_and_b' =&gt; &quot;($a,$b)&quot;

    sub foo : a_and_b { 
        # $a and $b are here set to what we knew as $_[0] and $_[1]
    }</pre>
<p>Now, yes, I am suggesting that there be a <code>attributes::prototype</code>
pragma, but that's not the thrust of my RFC - the point is how you
implement it, and you have to do this by making the prototype available.</p>
<p>That's the motivation; the justification is slightly different, and it's
to increase the flexibility and the possibilities for introspection that
Perl 6's subroutines provide the user. More flexibility is always a good
thing.</p>
<a name='IMPLEMENTATION'></a><h1>IMPLEMENTATION</h1>
<p>There are a number of ways that this can be done; I'd originally thought
that there should be Yet Another Special Variable, but it seems more
Perlish to change <code>prototype</code> to be a function which returns
the prototype of a built-in (same as Perl 5) or, when passed a fully
qualified sub name, an lvaluable subroutine to get or set the prototype
of that sub.</p>
<p>So <code>attributes::prototype</code> can then be implemented something vaguely
like this: store &quot;prototype class&quot; declarations in a hash, say,
<code>%PROTOS</code>; register the new attributes; when the attribute is
processed, set <code>prototype($sub) = $PROTOS{$attr}</code>.</p>
<a name='REFERENCES'></a><h1>REFERENCES</h1>
<p>RFC 57: Subroutine prototypes and parameters</p>
</div>
